package com.example.myapplication.ui.movie

import android.R.attr.fragment
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.bumptech.glide.Glide
import com.example.android_program.data_class.movie_1_1
import com.example.android_program.data_class.movie_2_1
import com.example.android_program.data_class.movie_2_2
import com.example.android_program.data_class.movie_2_3
import com.example.myapplication.MovieDetailsActivity
import com.example.myapplication.R
import com.example.myapplication.ui.home.HomeFragment

import com.google.android.material.tabs.TabLayout
import com.youth.banner.BannerConfig
import com.youth.banner.Transformer
import com.youth.banner.loader.ImageLoader
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_movie_tobeshown.*
import kotlinx.android.synthetic.main.fragment_movie_wellreceived.*
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONArray
import java.lang.Exception
import java.lang.StringBuilder
import java.lang.reflect.Field
import kotlin.concurrent.thread


class MovieFragment : Fragment(){

    private val list: ArrayList<Fragment>? = ArrayList<androidx.fragment.app.Fragment>()


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val root = inflater.inflate(R.layout.fragment_movie, container, false)

//        val sectionsPagerAdapter = SectionsPagerAdapter(this.requireContext(), childFragmentManager)
//        val viewPager: ViewPager = root.findViewById(R.id.movie_vp_content)
//        viewPager.adapter = sectionsPagerAdapter
//        val tabs: TabLayout = root.findViewById(R.id.tabs_movie)
//        tabs.setupWithViewPager(viewPager)

        val tabs: TabLayout = root.findViewById(R.id.tabs_movie)
        val viewPager: ViewPager = root.findViewById(R.id.movie_vp_content)

        //设置标题
        val tabs_title:ArrayList<String> = ArrayList<String>()
        tabs_title.add("待映")
        tabs_title.add("热映")

        //加入fragment
        val tabs_fragments:ArrayList<Fragment> = ArrayList<Fragment>()
        tabs_fragments.add(ToBeShownFragment())
        tabs_fragments.add(WellReceivedFragment())

        //设置适配器
        viewPager.adapter = movieAdapter(tabs_title, tabs_fragments, childFragmentManager)
        tabs.setupWithViewPager(viewPager)

        return root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)


    }

    override fun onAttach(activity: Activity) {
        super.onAttach(activity)


    }
}



